package com.project.personnel.config;

import com.google.code.kaptcha.impl.DefaultKaptcha;
import com.google.code.kaptcha.util.Config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

import java.util.Properties;

//验证码
@Configuration
@Component
public class KaptchaConfig {
    @Bean
    public DefaultKaptcha getKaptcheCode() {
        DefaultKaptcha defaultKaptcha = new DefaultKaptcha();
        Properties properties = new Properties();
        //是否要边框，默认有
        properties.setProperty("kaptcha.border", "no");
        //边框颜色
        //properties.setProperty("kaptcha.textproducer.font.color", "black");
        //图片宽度，默认200
        properties.setProperty("kaptcha.image.width", "150");
        //图片高度，默认50
        properties.setProperty("kaptcha.image.height", "50");
        //字符大小，默认40
        properties.setProperty("kaptcha.textproducer.font.size", "30");
        //session key,KAPTCHA_SESSION_KEY
        properties.setProperty("kaptcha.session.key", "code");
        //字符长度，默认5
        properties.setProperty("kaptcha.textproducer.char.length", "5");
        //字体样式，默认new Font("Arial",1,fontSize),new Font("Courier",1,fontSize)
        properties.setProperty("kaptcha.textproducer.font.names", "彩云,宋体,楷体,微软雅黑");
        //图片样式，水纹com.google.code.kaptcha.impl.WaterRipple 鱼眼com.google.code.kaptcha.impl.FishEyeGimpy 阴影com.google.code.kaptcha.impl.ShadowGimpy
        properties.setProperty("kaptcha.obscurificator.impl", "com.google.code.kaptcha.impl.ShadowGimpy");
        //验证码生成规则
        //properties.setProperty("kaptcha.textproducer.impl","");
        //字符间距，默认2
        properties.setProperty("kaptcha.textproducer.char.space","2");
        //验证码干扰颜色,默认为Color.BLACK
        properties.setProperty("kaptcha.noise.color","Color.BLACK");
        //干扰实现类com.google.code.kaptcha.impl.NoNoise
        properties.setProperty("kaptcha.noise.impl", "com.google.code.kaptcha.impl.NoNoise");
        //背景颜色渐变，开始
        properties.setProperty("kaptcha.background.clear.from", "232,240,254");
        //背景颜色渐变，结束
        properties.setProperty("kaptcha.background.clear.to", "232,240,254");
        Config config = new Config(properties);
        defaultKaptcha.setConfig(config);
        return defaultKaptcha;
    }
}
